package com.zx.map.controller.timer;

import com.zx.map.service.CreditRepayInfoService;
import com.zx.map.service.model.CreditRepayInfoModel;
import com.zx.mobile.MobileCommonHelper;
import com.zx.mobile.service.proxy.MessageSendProxy;
import com.zx.scp.service.model.MessageResponse;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 信用卡提醒服务
 *
 * @author Administrator
 */
public class NotifyRepayTimerController {
    /**
     * log
     */
    private static Logger log = Logger.getLogger(NotifyRepayTimerController.class);
    @Autowired
    private CreditRepayInfoService creditRepayInfoService;

    /**
     * 批量信用卡还款提醒
     * 逐笔扫描绑定信用卡信息   根据是否提醒  以及提醒日期 进行短信通知
     * 
     */
    public void notifyRepay() {
        try {
        	Date date = new Date();
            log.info("批量信用卡还款提醒开始时间，" + date);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            //查询 系统中 当日待提醒信用卡记录
            CreditRepayInfoModel param = new CreditRepayInfoModel();
            param.setNotifyFlag("1");//需要提醒服务
            param.setNotifyDate(Integer.toString(day));//当天日期 
            List<CreditRepayInfoModel> creditList =  creditRepayInfoService.getListByModel(param);
            
            //获取总记录数  按批次逐一提交  默认批次大小 50
            int listSize = creditList.size();
            log.info("批量信用卡还款提醒：总记录，" + listSize);
            for(CreditRepayInfoModel oo : creditList)
            {
            	// 传递手机号
				MessageResponse response = MessageSendProxy
						.getMessageResponse(
								MobileCommonHelper.MESSAGETYPE_CREDITNOTIFY,
								oo.getMerSysAccount());
				log.info("信用卡还款提醒返回:"+ToStringBuilder.reflectionToString(response));
            }
            log.info("批量信用卡还款提醒结束时间" + new Date());

        } catch (Exception e) {
            log.error("批量信用卡还款提醒异常", e);
        }
    }
}
